This challenge uses data from https://happyplanetindex.org. On that website a community of international organisations and indidviduals publish an index - the Happy Planet Index - which is meant as an alternative to mainstream indicators of ecological growth.
As stated on the website: “Our current ecological system is driven by a ‘growth at all costs’ mentality, as measured by Gross Domestic Product (GDP). There is an entrenched belief that GDP growth is synonymous with increasing wellbeing and prosperity and is universally beneficial. In reality, GDP growth on its own does not mean a better life for everyone, particularly in countries that are already wealthy. It doesn’t take into account inequality, the things that really matter to people like social relations, health, or how they spend their free time, and crucially, the planetary limits we are up against.”
The Happy Planet Index (HPI) is computet from three variables: (1) life expectancy, (2) experienced wellbeing, (3) ecological footprint. The first two contribute positively to the index, the third one contributes negatively to the index. You can find the details here, in particular a precise definition of the variables (page 3 and 4). The data set also contains the variable GDP per capita, although it is not used for the computation of the Happy Planet Index.
# Load your packages here
library(tidyverse)
library(sf)
library(rnaturalearth)
library(GGally)
library(plotly)
library(viridis)# Read in the data set here
hpi <- read.csv(file = 'happy-planet-index.csv')gdp_capita,
experienced_wellbeing, footprint and
life_expectancy related to the Happy Planet Index
hpi? And how are these variables interrelated?# instantiating and storing data of the year 2019 in hpi_2019
hpi_2019 <- hpi %>%
filter(year == 2019)# correlation matrix configuration
ggcorr(hpi_2019[, 5:9], color = "grey35", size = 4, hjust = 0.8, label = TRUE) +
ggplot2::labs(title = "Correlation Coefficient of the Variables", caption = 'https://happyplanetindex.org') +
ggplot2::theme(legend.position = "right") + scale_fill_viridis() Analysing the correlation matrix we can make some observations:
# selecting subset of country names to display in plot
names <- hpi_2019 %>% filter(
country == 'Qatar' |
country == 'Denmark' |
country == 'India' |
country == 'Afghanistan' |
country == 'Costa Rica')
# building individual plots
fig1 <- plot_ly(data = hpi_2019, x = ~experienced_wellbeing, y = ~hpi, type = 'scatter')
fig1 <- plot_ly(data = hpi_2019, x = ~experienced_wellbeing, y = ~hpi) %>%
add_annotations(x = names$experienced_wellbeing,
y = names$hpi,
text = names$country,
xref = "x",
yref = "y",
showarrow = TRUE,
arrowhead = 4,
arrowsize = .5,
ax = 20,
ay = -40)
fig2 <- plot_ly(data = hpi_2019, x = ~footprint, y = ~hpi, type = 'scatter')
fig2 <- plot_ly(data = hpi_2019, x = ~footprint, y = ~hpi) %>%
add_annotations(x = names$footprint,
y = names$hpi,
text = names$country,
xref = "x",
yref = "y",
showarrow = TRUE,
arrowhead = 4,
arrowsize = .5,
ax = 20,
ay = -40)
fig3 <- plot_ly(data = hpi_2019, x = ~lifeexp, y = ~hpi, type = 'scatter')
fig3 <- plot_ly(data = hpi_2019, x = ~lifeexp, y = ~hpi) %>%
add_annotations(x = names$lifeexp,
y = names$hpi,
text = names$country,
xref = "x",
yref = "y",
showarrow = TRUE,
arrowhead = 4,
arrowsize = .5,
ax = 20,
ay = -40)
fig4 <- plot_ly(data = hpi_2019, x = ~gdp_capita, y = ~hpi, type = 'scatter')
fig4 <- plot_ly(data = hpi_2019, x = ~gdp_capita, y = ~hpi) %>%
add_annotations(x = names$gdp_capita,
y = names$hpi,
text = names$country,
xref = "x",
yref = "y",
showarrow = TRUE,
arrowhead = 4,
arrowsize = .5,
ax = 20,
ay = -40)
# combining individual plots to subplot
fig <- subplot(fig1, fig2, fig3, fig4, nrows = 2, margin = 0.05) %>%
layout(title = 'Happy Planet Index vs. Variables',
plot_bgcolor='#e5ecf6',
margin = 0.05)
# configuring annotations
annotations = list(
list(
x = 0.2,
y = 1.05,
text = "Experienced Wellbeing",
xref = "paper",
yref = "paper",
xanchor = "center",
yanchor = "bottom",
showarrow = FALSE
),
list(
x = 0.8,
y = 1.05,
text = "Ecological Footprint",
xref = "paper",
yref = "paper",
xanchor = "center",
yanchor = "bottom",
showarrow = FALSE
),
list(
x = 0.2,
y = -0.15,
text = "Life Expectancy",
xref = "paper",
yref = "paper",
xanchor = "center",
yanchor = "bottom",
showarrow = FALSE
),
list(
x = 0.8,
y = -0.15,
text = "GDP per Capita",
xref = "paper",
yref = "paper",
xanchor = "center",
yanchor = "bottom",
showarrow = FALSE
),
list(
x = 1.1, y = -0.25, text = "https://happyplanetindex.org",
showarrow = F, xref='paper', yref='paper',
xanchor='right', yanchor='auto', xshift=0, yshift=0,
font=list(size=8, color="black"))
)
# adding annotations
fig <- fig %>%layout(annotations = annotations, showlegend = FALSE)
# printing plot
figFrom the observations we might deduce that the wealth of country doesn’t have an influence on the happiness of it’s citizens. Furthermore the it shows that countries with larger gross domestic product will have a higher ecological footprint.
Life expectancy imposes a linear upper bound on the Happy Planet Index: For a given life expectancy, there is a maximum value above which the Happy Planet Index can not rise. The same is true for experienced wellbeing and ecological footprint. Though the slope of the boundary of is positive for Experienced Wellbeing and Life Expectancy but negative for Ecological Footprint.
Countries with a high ecological footprint also appear to have an upper bound on the Happy Planet Index: most notably in that case is Qatar
This is similar but not as pronounced between the Happy Planet Index of a country and it’s GDP per Capita.
In conclusion we find:
lifeexp, experienced_wellbeing,
footprint, and hpi between 2006 and 2020.# focus only on the country Zimbabwe between 2006 and 2020.
hpi_zwe <- hpi %>% arrange(year) %>% filter(country =="Zimbabwe" & year >= 2006 & year <= 2020)
hpi_zwe_chng <- hpi_zwe %>%
mutate(hpi_perc = ((hpi - hpi[1L]) / hpi[1L])*100) %>%
mutate(lifeexp_perc = ((lifeexp - lifeexp[1L]) / lifeexp[1L])*100) %>%
mutate(experienced_wellbeing_perc = ((experienced_wellbeing-experienced_wellbeing[1L]) / experienced_wellbeing[1L])*100) %>%
mutate(footprint_perc = ((footprint-footprint[1L]) / footprint[1L])*100)
fig <- plot_ly(hpi_zwe_chng, x = ~year, y = ~hpi_perc, name = 'Happy Planet Index', type = 'scatter', mode = 'lines', line = list(width = 3))
fig <- fig %>% add_trace(y = ~lifeexp_perc, name = 'Life Expectancy', line = list(width = 1))
fig <- fig %>% add_trace(y = ~experienced_wellbeing_perc, name = 'Experienced Wellbeing', line = list(width = 1))
fig <- fig %>% add_trace(y = ~footprint_perc, name = 'Footprint', line = list(width = 1))
fig <- fig %>% layout(title = "Development of Zimbabwe",
plot_bgcolor='#e5ecf6',
margin = 0.05,
xaxis = list(title = "Year"),
yaxis = list(title = "Change in % since 2006"),
annotations = list(
x = 1.3, y = -0.2, text = "https://happyplanetindex.org",
showarrow = F, xref='paper', yref='paper',
xanchor='right', yanchor='auto', xshift=0, yshift=0,
font=list(size=8, color="black"))
)
figThe chart shows two distinct periods, from 2006 to 2012 and from 2012 to 2020.
During 2006 to 2012:
During 2012 to 2020:
Final observations:
# finding happiest country
arrange(hpi_2019, desc(hpi))[1, 2]## [1] "Costa Rica"
geo <- rnaturalearth::ne_countries(returnclass = "sf") %>%
select(iso_a3, geometry)
sf <- hpi_2019 %>%
right_join(geo, by = c("iso"="iso_a3")) %>%
st_as_sf()
# finding coordinates online:
# Latitude: 9.6301892 Longitude: -84.2541844
map <- ggplot(data = sf, mapping = aes(fill = hpi)) +
geom_sf() +
coord_sf(crs = "+proj=laea +lat_0=9 +lon_0=-84 +ellps=GRS80 +units=m +no_defs ", expand = FALSE) +
scale_fill_viridis_c(begin = 0.1)
map +
labs(
title = "Lambert azimuthal equal-area projection",
fill = "Happy Planet Index",
caption = 'https://happyplanetindex.org')hpi_per_continent <- hpi %>%
group_by(continent)
fig <- hpi_per_continent %>%
plot_ly(
x = ~continent,
y = ~hpi,
split = ~continent,
type = 'violin',
points = FALSE,
box = list(visible = T),
meanline = list(visible = T))
fig <- fig %>%
layout(
title = "HPI Distribution per Continent",
margin = 0.05,
plot_bgcolor='#e5ecf6',
xaxis = list(
title = "Continents"),
yaxis = list(
title = "Happy Planet Index",
zeroline = F),
annotations = list(
x = 1.5, y = -0.45, text = "https://happyplanetindex.org",
showarrow = F, xref='paper', yref='paper',
xanchor='right', yanchor='auto', xshift=0, yshift=0,
font=list(size=8, color="black")))
fig When comparing the mean of the continents, we find:
When comparing the distributions of the continents, we find:
When comparing continents directly, there are also some curiosities: